<% content_for :sidebar do %>
  <%= sidebar_button_link 'Edit Event',
           edit_event_path(@event) if can? :edit, @event %>
  <%= sidebar_button_link 'New Task',
           new_event_task_path(@event) if can? :create, Task %>
  <%= sidebar_button_link 'New Availability',
           new_event_availability_path(@event) if can? :create, Availability %>
  <%= sidebar_button_link "New Notification",
           new_event_notification_path(@event) if can? :create, Notification %>
  <%= sidebar_button_link "New Timecard",
           new_timecard_path(event: @event) if can? :create, Timecard %>
  <%= sidebar_button_link "Next Event",
           event_path(next_event(@event)) if can?(:show, Timecard) && next_event(@event)%>
  <%= sidebar_button_link "Previous Event",
           event_path(previous_event(@event)) if can?(:show, Timecard) && previous_event(@event) %>
<% end %>

<ol class="breadcrumb">
  <li class="breadcrumb-item"><%= link_to 'Events', events_path %></li>
  <li class="breadcrumb-item active"><%= @event.title %></li>
</ol>

<p>
  <span class="h3">
    <% if @event.category.present? %>
      <b><%= @event.category %>:</b>
    <% end %>
    <%= @event.title %>
  </span>
  <% if @event.location.present? %>
    at <%= @event.location %>
  <% end %>
  (<%= format_time_span(@event.start_time, @event.end_time, @event.duration) %>)
</p>

<% if @event.description.present? %>
  <p><b>Description:</b> <%= @event.description %></p>
<% end %>

<p><b> Minimum Event Rank:</b> <%= @event.min_title %></p>

<p><b>Code:</b> <%= @event.id_code %></p>

<p><b>Departments:</b> <%= @event.departments.map { |d| d.name }.join(', ') %></p>

<% if @event.category == "Training" %>
  <p><%= @event.course.blank? ? "Training" : @event.course.name %> by <%= @event.instructor %></p>
<% end %>

<p><%= event_status_label(@event) %></p>

<table id="event-status" class="table table-nonfluid">
  <thead><tr>
    <td><strong>Department</strong></td>
    <td><strong>Responses</strong></td>
  </tr></thead>
  <tbody>
    <% @event.departments.each do |department| %>
      <%= content_tag 'tr', id: "#{department.name.parameterize}-status" do %>
        <td><%= department.name %></td>
        <td><%= display_event_status_by_dept(@event, department) %></td>
      <% end %>
    <% end %>
  </tbody>
</table>

<div class='event-tabs'>
  <ul class="nav nav-tabs">
    <li class="active"><a class='event-tabs-anchor' href="#event-task-tab" data-toggle="tab">Tasks</a></li>
    <li><a class='event-tabs-anchor' href="#event-availability-tab" data-toggle="tab">Availabilities</a></li>
    <li><a class='event-tabs-anchor' href='#event-notification-tab' data-toggle="tab">Notifications</a></li>
    <li><a class='event-tabs-anchor' href='#event-timecards-tab' data-toggle="tab">Timecards</a></li>
  </ul>

  <div class="tab-content">
    <div class="tab-pane active" id="event-task-tab">
      <%= render(partial: 'tasks/tasks_table', locals: { tasks: @event.tasks}) %>
    </div>
    <div class="tab-pane" id="event-availability-tab">
      <div id="event_availabilities" >
        <%= render(:partial => "availabilities/availabilities_table",
                   :locals => { :availabilities => @responses_and_assignments })
        %>

        <%= render(partial: "people/people_table",
                   locals: { people: @event.unresponsive_people,
                             title: "No Response" })
        %>
      </div>
    </div>
    <div class="tab-pane" id="event-notification-tab">
      <%= render(partial: 'notifications/notifications_table',
                 locals: { notifications: @event.notifications }) %>
    </div>
    <div class="tab-pane" id="event-timecards-tab">
      <%= render 'timecards/timecards_table', timecards: @timecards %>
    </div>
  </div>
</div>

<% if @event.comments.present? %>
  <p><b>Comments:</b> <%= @event.comments %></p>
<% end %>
<p>
  Created <%= @event.created_at %><br/>
  Last Modified <%= @event.updated_at %></br>
  Last Editor <%= @last_editor %>
</p>
